import json

from flask import request,jsonify

from utils.jwtc import token1
from flask import Blueprint
from utils.acl import acl
from utils.redosconn import r
from utils.comm import get_data
from utils.db import db1


bp_user = Blueprint('user',__name__)

# 登陆
@bp_user.route('/login',methods=['GET'])
def login():
    name = request.args.get("name")
    password = request.args.get("password")
    print(name,password)
    sql = "select * from user where name='%s' and password='%s'"%(name,password)
    res = db1.find(sql)
    print(res)
    if res:
          vurl = acl.get_page_reslist(res['id'])
          key = "inter"+str(res['id'])
          r.insert_values(key,vurl)
          # data = {'data':{'name':res['name'],'userid':res['id']}}
          # token = token1.encode_jwt(data)
          token = token1.encode_jwt(int(res["id"]), 60 * 60, "123")
          return jsonify({'code':200,'userid':res['id'],"token":token,"vurl":vurl})
    else:
        return jsonify({"code":20020,"msg":'登陆失败'})















